package com.acme.bankapp.domain.bank;

import com.acme.bankapp.service.bank.NotEnoughFundsException;

public abstract class AbstractAccount implements Account {
	// using protected to allow subclasses to modify it
	protected int id;
	protected double balance;

	// using final to prevent confusion caused by unexpectedly changed value of
	// variable
	public AbstractAccount() {
	}

	public AbstractAccount(final double amount) throws IllegalArgumentException {
		this.balance = amount;
		if (amount < 0)
			throw new IllegalArgumentException(
					"Account is not added! Balance is negative");
	}

	public double getBalance() {
		return balance;
	}

	public void deposit(final double amount) {
		balance += amount;
		System.out.println("Successfully, " + amount
				+ " was deposited to account");
	}

	public void withdraw(final double amount) throws NotEnoughFundsException {
		if (this.balance >= amount) {
			this.balance -= amount;
			System.out.println("Successfully, " + amount
					+ " was withdrawn from account");
		} else {
			throw new NotEnoughFundsException(
					"Not enough money in the account: requested " + amount
							+ ", have " + this.balance + " only");
		}
	}

	public double maximumAmountToWithdraw() {
		return this.balance;
    }
}